<template>
  <Dialog custom-class="test" title="群成员" v-model="dialogVisible" width="1400">
    <ContentWrap>
      <el-table v-loading="loading" border :header-cell-style="{ background: '#f0f0f0' }" :data="list" :stripe="true" :show-overflow-tooltip="true">
        <el-table-column label="用户名称" align="center" prop="name" width="200px" />
        <el-table-column label="群聊昵称" align="center" prop="groupNickname" />
        <el-table-column label="是否管理员" align="center" prop="isAdmin">
          <template #default="scope">
            <span v-if="scope.row.isAdmin">是</span>
            <span v-else>否</span>
          </template>
        </el-table-column>
        <el-table-column label="成员类型" align="center" prop="type">
          <template #default="scope">
            <span v-if="scope.row.type == 1">员工</span>
            <span v-if="scope.row.type == 2">外部联系人</span>
          </template>
        </el-table-column>
        <el-table-column
          label="加入时间"
          align="center"
          prop="joinTime"
          :formatter="dateFormatter"
          width="180px"
        />
        <el-table-column label="加入方式" align="center" prop="joinScene">
          <template #default="scope">
            <span v-if="scope.row.type == 1">直接邀请</span>
            <span v-if="scope.row.type == 2">链接邀请</span>
            <span v-if="scope.row.type == 3">扫码</span>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <Pagination
        :total="total"
        v-model:page="queryParams.pageNo"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </ContentWrap>
  </Dialog>
</template>
<script setup lang="ts">
import * as WeChatGroupApi from '@/api/wecom/chatgroup'
import { dateFormatter } from '@/utils/formatTime'

const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗

const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  chatGroupId: undefined
})

const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据

const dialogVisible = ref(false) // 弹窗的是否展示
/** 打开弹窗 */
const open = async (id?: number) => {
  dialogVisible.value = true
  if (id) {
    try {
      queryParams.chatGroupId = id
      await getList()
    } finally {
      loading.value = false
    }
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await WeChatGroupApi.getWeChatGroupMember(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

</script>
<style scoped lang="scss">
.test {
  ::deep(.el-dialog__body) {
    padding-bottom: 100px !important;
  }
}
</style>